<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta property="og:type" content="website">
<meta property="og:title" content="smallmuou&#39;s blog">
<meta property="og:url" content="http://smallmuou.gitee.io/blog/page/5/index.html">
<meta property="og:site_name" content="smallmuou&#39;s blog">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="smallmuou&#39;s blog">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://smallmuou.gitee.io/blog/page/5/"/>





  <title>smallmuou's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">smallmuou's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"><a href="https://github.com/smallmuou">https://github.com/smallmuou</a></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/12/27/2017-12-27-iPhone蓝牙靠近解锁/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/12/27/2017-12-27-iPhone蓝牙靠近解锁/" itemprop="url">iPhone蓝牙靠近解锁</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-27T00:00:00+08:00">
                2017-12-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/IOS/" itemprop="url" rel="index">
                    <span itemprop="name">IOS</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>之前购买了一款APP - NearLock，可以通过iPhone蓝牙靠近解锁Mac，一旦在一定距离内，Mac就会自动解锁，而离开后，Mac又会自动上锁，挺方便的，虽然偶尔也会抽风，于是近期正好接触蓝牙，也简单实现了个类似的DEMO，本文将描述这其中的整个思路。</p>
<h3 id="蓝牙BLE知识普及"><a href="#蓝牙BLE知识普及" class="headerlink" title="蓝牙BLE知识普及"></a>蓝牙BLE知识普及</h3><p>随着蓝牙4.0低功耗的推出，蓝牙便得到了很多支持，几乎所有的智能手机都配置了蓝牙模块。如果要了解蓝牙的整个协议栈，那将非常乏味，我这里只介绍ATT部分，即蓝牙应用层.</p>
<p>待续。。。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/12/26/2017-12-26-查看二进制文件的末尾N字节/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/12/26/2017-12-26-查看二进制文件的末尾N字节/" itemprop="url">查看二进制文件的末尾N字节</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-26T00:00:00+08:00">
                2017-12-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>查看二进制文件末尾N个字节 <code>xxd -s length-N file</code></p>
<p>PS: length为文件总大小</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">$ ls -al spark_2_8_3.dmg</span><br><span class="line">-rw-r--r--@ 1 smou  staff  99555201 Dec 22 16:02 spark_2_8_3.dmg</span><br><span class="line"></span><br><span class="line">$ xxd -s 99555100  spark_2_8_3.dmg</span><br><span class="line">05ef171c: 0000 0000 0000 0000 0000 0000 0000 0000  ................</span><br><span class="line">05ef172c: 0000 0000 0000 0000 0000 0000 0000 0000  ................</span><br><span class="line">05ef173c: 0000 0000 0000 0000 0000 0000 0000 0000  ................</span><br><span class="line">05ef174c: 0000 0000 0000 0000 0000 0000 0000 0000  ................</span><br><span class="line">05ef175c: 0000 0000 0000 0000 0000 0000 0000 0000  ................</span><br><span class="line">05ef176c: 0100 0000 0000 06b0 6c00 0000 0000 0000  ........l.......</span><br><span class="line">05ef177c: 0000 0000 00                             .....</span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/12/22/2017-12-22-wipefs病毒排查过程/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/12/22/2017-12-22-wipefs病毒排查过程/" itemprop="url">wipefs病毒排查过程</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-22T00:00:00+08:00">
                2017-12-22
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>最近服务器被植入病毒了，现象是ssh经常卡死，于是我使用vnc登录至服务器</p>
<h4 id="1-发现原因"><a href="#1-发现原因" class="headerlink" title="1. 发现原因"></a>1. 发现原因</h4><p>我使用top后，发现某个进程占用非常高cpu，在100%以上，而且只持续了几十秒，在这期间，ssh就卡死了</p>
<h4 id="2-分析"><a href="#2-分析" class="headerlink" title="2. 分析"></a>2. 分析</h4><p>我对该进程进行了分析，发现是/bin/qgjrlxsuzx，看了下是个二进制文件，因此我备份了相关文件，并删除该可执行文件及相应的开启启动配置、最后kill相应进程</p>
<h4 id="3-重新出现"><a href="#3-重新出现" class="headerlink" title="3. 重新出现"></a>3. 重新出现</h4><p>本以为问题解决了，可一段时间后，发现ssh还是卡死，于是又进行了分析，发现又有另一个名称rzacovihtr的可执行文件，我看了下文件创建时间，发现是刚创建的，于是我kill进程，发现又产生了另外一个</p>
<p>于是我初步得出，应该有一个幕后老大，可如何找出呢？</p>
<h4 id="4-发现源头"><a href="#4-发现源头" class="headerlink" title="4. 发现源头"></a>4. 发现源头</h4><p>竟然会自动产生子进程，那应该也有自己的进程，于是我通过top、ps不断地观察可疑进程，最终我发现wipefs进程，并且查了下资料，发现原来是挖矿程序，于是我备份了文件并删除可执行文件/bin/wipefs</p>
<h4 id="5-结束"><a href="#5-结束" class="headerlink" title="5. 结束"></a>5. 结束</h4><p>通过一段时间观察，cpu恢复了正常，而且ssh没有再断开，因此该问题也告一段落。</p>
<h4 id="6-遗憾"><a href="#6-遗憾" class="headerlink" title="6. 遗憾"></a>6. 遗憾</h4><p>虽然搞清楚了病毒，但对如何植入还是不清楚，还留有小小遗憾 …</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/11/29/2017-11-29-测试带宽常用方法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/11/29/2017-11-29-测试带宽常用方法/" itemprop="url">测试带宽常用方法</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-29T00:00:00+08:00">
                2017-11-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>很多时候，我们为了排查问题，往往需要了解对方网络带宽，下面给出几种方法：</p>
<ul>
<li>方法1：登录speedtest测速网，点击开始测速</li>
</ul>
<p><img src="http://ovjgvf1tp.bkt.clouddn.com/speedtest-output.png" alt="" title="Optional title"></p>
<ul>
<li>方法2：使用speedtest-cli</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">root:~ $ speedtest-cli</span><br><span class="line">Retrieving speedtest.net configuration...</span><br><span class="line">Testing from China Telecom fujian (59.61.184.111)...</span><br><span class="line">Retrieving speedtest.net server list...</span><br><span class="line">Selecting best server based on ping...</span><br><span class="line">Hosted by China Unicom FuJian (Fuzhou) [1.63 km]: 25.097 ms</span><br><span class="line">Testing download speed................................................................................</span><br><span class="line">Download: 35.41 Mbit/s</span><br><span class="line">Testing upload speed................................................................................................</span><br><span class="line">Upload: 47.07 Mbit/s</span><br></pre></td></tr></table></figure>
<ul>
<li>方法3：采用iperf</li>
</ul>
<p>以上方法都要依赖speedtest，而最近发现speedtest不给力，因此找到了iperf。iperf是一个非常好用的命令，分服务端工作模式和客户端工作模式</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">iperf [-s|-c host] [options]</span><br><span class="line"></span><br><span class="line">-i 时间间隔</span><br><span class="line">-p 指定端口</span><br><span class="line">-u UDP</span><br><span class="line">-d 双向</span><br><span class="line">-s 服务端</span><br><span class="line">-c 客户端</span><br><span class="line">-t 测试时间</span><br><span class="line">-b 指定发送速率</span><br></pre></td></tr></table></figure>
<p>样例</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 服务端</span></span><br><span class="line">root:~ $ iperf -s -i 1 -u</span><br><span class="line">------------------------------------------------------------</span><br><span class="line">Server listening on UDP port 5001</span><br><span class="line">Receiving 1470 byte datagrams</span><br><span class="line">UDP buffer size:  208 KByte (default)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 客户端</span></span><br><span class="line">smou:~ $ iperf -c 192.168.12.200 -i 1 -t 10 -b 30M</span><br><span class="line">WARNING: option -b implies udp testing</span><br><span class="line">------------------------------------------------------------</span><br><span class="line">Client connecting to 192.168.12.200, UDP port 5001</span><br><span class="line">Sending 1470 byte datagrams</span><br><span class="line">UDP buffer size: 9.00 KByte (default)</span><br><span class="line">------------------------------------------------------------</span><br><span class="line">[  4] <span class="built_in">local</span> 192.168.12.101 port 60797 connected with 192.168.12.200 port 5001</span><br><span class="line">[ ID] Interval       Transfer     Bandwidth</span><br><span class="line">[  4]  0.0- 1.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  1.0- 2.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  2.0- 3.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  3.0- 4.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  4.0- 5.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  5.0- 6.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  6.0- 7.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  7.0- 8.0 sec  3.57 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  8.0- 9.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  9.0-10.0 sec  3.58 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4]  0.0-10.0 sec  35.8 MBytes  30.0 Mbits/sec</span><br><span class="line">[  4] Sent 25510 datagrams</span><br><span class="line">[  4] Server Report:</span><br><span class="line">[  4]  0.0- 9.9 sec  35.4 MBytes  29.9 Mbits/sec   0.393 ms  233/25509 (0.91%)</span><br><span class="line">[  4]  0.0- 9.9 sec  1 datagrams received out-of-order</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/11/28/2017-11-28-如何解决umount提示设备忙问题/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/11/28/2017-11-28-如何解决umount提示设备忙问题/" itemprop="url">如何解决umount提示设备忙问题</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-28T00:00:00+08:00">
                2017-11-28
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>每当我们需要卸载硬盘，经常会提示<code>device is busy</code>，即设备忙，今天为大家介绍一款工具 — lsof, 通过它就可以看出谁占用了该设备。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_137_246_centos mnt]<span class="comment"># lsof +D /mnt/</span></span><br><span class="line">COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME</span><br><span class="line">bash    1292 root  cwd    DIR  252,1     4096 65537 /mnt</span><br><span class="line">lsof    2939 root  cwd    DIR  252,1     4096 65537 /mnt</span><br><span class="line">lsof    2940 root  cwd    DIR  252,1     4096 65537 /mnt</span><br></pre></td></tr></table></figure>
<p>我们可以看到是由于我们进入了mnt目录，导致cwd占用了mnt，我们只要把所有PID都kill，就可以成功卸载或者删除.</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/11/28/2017-11-28-重启腾讯云服务器后导致数据遗失问题排查/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/11/28/2017-11-28-重启腾讯云服务器后导致数据遗失问题排查/" itemprop="url">重启腾讯云服务器后导致数据遗失问题排查</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-28T00:00:00+08:00">
                2017-11-28
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>近日，遇到一个非常奇怪的问题：<code>重启腾讯云服务器后导致数据遗失，即整个/var下的内容都不见了，而且mysql、sshd都无法启动</code>. 针对以上问题，经过了一个下午的排查，最终确定是由于挂载了新硬盘导致原数据看不到。如果你只想关注结果，本文就到此结束了，然而我更想把整个排查过程分享于此。最近在看电视剧《神探狄仁杰》，非常精彩，试想一下，如果一下子给出谁是凶手，就没有那么精彩了，其给出的往往是一些蛛丝马迹，通过这些蛛丝马迹慢慢推出凶手；排查问题跟断案也是一个道理，我们可以根据已有的蛛丝马迹，推出真正的『凶手』。</p>
<p><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3779694246,1344206214&amp;fm=27&amp;gp=0.jpg" alt="" title="Optional title"></p>
<h5 id="蛛丝马迹"><a href="#蛛丝马迹" class="headerlink" title="蛛丝马迹"></a>蛛丝马迹</h5><ul>
<li>头一次重启非常慢，大致花费了5分钟，后面重启时间正常</li>
<li>启动后发现ssh无法登录，提示/var/empty/xxx文件不存在</li>
<li>mysql启动失败，提示/var/lib/mysql/xxx不存在</li>
<li>外挂50G硬盘，只分配了10G</li>
</ul>
<h5 id="推敲"><a href="#推敲" class="headerlink" title="推敲"></a>推敲</h5><ul>
<li>会不会被误删</li>
</ul>
<p>根据以上的蛛丝马迹，我们把问题定位在/var，即由于/var中文件遗失，导致服务异常，于是我们确认了下/var，确实没有相应的文件，而没有很可能被误删除了，我们查了下history，发现并没有类似的操作；</p>
<ul>
<li>会不会是盘损坏，重新初始化</li>
</ul>
<p>我又重新确认了下/var，发现/var确实是外挂硬盘，于是我就猜想会不会是腾讯内部BUG引发硬盘损坏，重新初始化，于是自己就把自己推向的死路，至此冤案就产生了，认定腾讯云不可靠。</p>
<ul>
<li>偶然卸载硬盘</li>
</ul>
<p>也是事情到此就结束了，带着无数的疑问长埋于地下，然而事情就是这么偶然，由于之前的硬盘只分配了10G，于是我想重新分配下，因此我就卸载了硬盘，并重启了，然而神奇的事情就发生了，mysql服务正常了，查看/var，发现原来的文件都像变戏法般还原了。</p>
<ul>
<li>确定出真正元凶</li>
</ul>
<p>于是分析了下，终于确定了是由于挂载了新硬盘，导致原/var下的内容神奇的消失了。而且忽然想到，腾讯云新分配的硬盘，需要重启才能生效，而且硬盘初始化需要一段时间，这也就解释了为何头一次重启需要花费5分钟时间。</p>
<h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><p>唯有真正元凶，才会让所有现象都变得很好解释，否则很有可能产生冤案.</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/11/27/2017-11-27-衡量网络好坏的指标QoS/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/11/27/2017-11-27-衡量网络好坏的指标QoS/" itemprop="url">衡量网络好坏的指标QoS</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-27T00:00:00+08:00">
                2017-11-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>前段时间看过华为的《QoS 技术白皮书》，写的很不错，这里记录下关键的点，以备不时之需。</p>
<p>QoS（Quality of Service）是衡量一个网络好坏的指标，它采用如下参数来度量：</p>
<ul>
<li>带宽/吞吐量</li>
<li>时延</li>
<li>抖动（时延变化）</li>
<li>丢包率</li>
</ul>
<p>以下对其概念及常用业务指标进行描述</p>
<h3 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h3><ul>
<li>带宽/吞吐量</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">带宽（bandwidth）也称为吞吐量（throughput），是指在一个固定的时间内（1 秒），从网络一端传输到另一端的最大数据位数，也可以理解为网络的两个节点之间特定数据流的平均速率。带宽的单位是比特/秒（bit/s，简写为 bps）。带宽分为&quot;上行带宽&quot; 和 &quot;下行带宽&quot;。</span><br></pre></td></tr></table></figure>
<ul>
<li>时延</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">时延（Latency）是指一个报文或分组从网络的一端传送到另一端所需要的时间。</span><br></pre></td></tr></table></figure>
<ul>
<li>抖动</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">抖动（Jitter），是指同一业务流中不同分组所呈现的时延不同。抖动主要是由于业务流中相继分组的排队等候时间不同引起的，是对服务质量影响最大的一</span><br><span class="line">个问题。</span><br></pre></td></tr></table></figure>
<p>PS: 如把时延比作速度，则抖动可以理解为加速度</p>
<ul>
<li>丢包率</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">丢包率是指在网络传输过程中丢失报文占传输报文的百分比。</span><br></pre></td></tr></table></figure>
<h3 id="常见指标"><a href="#常见指标" class="headerlink" title="常见指标"></a>常见指标</h3><table>
<thead>
<tr>
<th style="text-align:left">业务类型</th>
<th style="text-align:left">带宽/吞吐量</th>
<th style="text-align:left">时延</th>
<th style="text-align:left">抖动</th>
<th style="text-align:left">丢包率</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">视频电话会议</td>
<td style="text-align:left">带宽需求高</td>
<td style="text-align:left">对时延非常敏感</td>
<td style="text-align:left">对抖动非常敏感</td>
<td style="text-align:left">要求可预计的时延和丢包率</td>
</tr>
<tr>
<td style="text-align:left">电子商务</td>
<td style="text-align:left">带宽需求适当</td>
<td style="text-align:left">对时延敏感</td>
<td style="text-align:left">对抖动敏感</td>
<td style="text-align:left">对丢包率敏感，必须可靠传输</td>
</tr>
<tr>
<td style="text-align:left">流媒体</td>
<td style="text-align:left">带宽需求高</td>
<td style="text-align:left">对时延比较敏感</td>
<td style="text-align:left">对抖动比较敏感</td>
<td style="text-align:left">要求可预计的时延和丢包率</td>
</tr>
<tr>
<td style="text-align:left">电子邮件、文件传输</td>
<td style="text-align:left">传输带宽需求低</td>
<td style="text-align:left">容许时延</td>
<td style="text-align:left">容许抖动</td>
<td style="text-align:left">尽力而为传送</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th style="text-align:left">业务类型</th>
<th style="text-align:left">时延</th>
<th style="text-align:left">抖动</th>
<th style="text-align:left">丢包率</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">视频电话会议</td>
<td style="text-align:left">≤50ms</td>
<td style="text-align:left">≤10ms</td>
<td style="text-align:left">≤0.1%</td>
</tr>
<tr>
<td style="text-align:left">电子商务</td>
<td style="text-align:left">≤200ms</td>
<td style="text-align:left">≤100ms</td>
<td style="text-align:left">TCP 保证</td>
</tr>
<tr>
<td style="text-align:left">流媒体</td>
<td style="text-align:left">≤1s</td>
<td style="text-align:left">≤200ms</td>
<td style="text-align:left">≤0.1%</td>
</tr>
<tr>
<td style="text-align:left">电子邮件、文件传输</td>
<td style="text-align:left">NA</td>
<td style="text-align:left">NA</td>
<td style="text-align:left">TCP 保证</td>
</tr>
</tbody>
</table>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/11/23/2017-11-23-使用nc命令发送或接收任意数据包/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/11/23/2017-11-23-使用nc命令发送或接收任意数据包/" itemprop="url">使用nc命令发送或接收任意数据包</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-23T00:00:00+08:00">
                2017-11-23
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>在网络问题的排查过程，我们经常需要去单方地验证客户端或服务端是否正常、以及网络是否可达，往往我们需要编写特定的测试代码，显得非常麻烦，今天将为大家介绍一个神器 —- nc</p>
<h5 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h5><blockquote>
<p>nc – arbitrary TCP and UDP connections and listens</p>
</blockquote>
<p>从定义可以看出，nc用于发送和监听任意TCP和UDP数据，因此我们可以模拟任意的客户端或服务端，下面我们来介绍下具体的使用方法</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">nc [OPTIONS] [hostname] [port[s]] </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">OPTIONS:（常用）</span><br><span class="line"></span><br><span class="line">    -4 强制使用ipv4</span><br><span class="line">    -6 强制使用ipv6</span><br><span class="line">    -l 监听</span><br><span class="line">    -p 指定源端口</span><br><span class="line">    -s 指定源IP</span><br><span class="line">    -n 采用数字，而非域名</span><br><span class="line">    -w 设置超时，单位秒</span><br><span class="line">    -u UDP</span><br><span class="line">    -v 输出详情</span><br><span class="line">    -U 采用本地套接字</span><br></pre></td></tr></table></figure>
<p>默认情况nc采用stdin作为输入，stdout作为输出</p>
<h5 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h5><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># for centos</span></span><br><span class="line">sudo yum install nc</span><br><span class="line"></span><br><span class="line"><span class="comment"># for debain</span></span><br><span class="line">sudo apt-get install nc</span><br></pre></td></tr></table></figure>
<h5 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h5><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment"># 监听1234端口</span></span><br><span class="line">nc -l 1234    </span><br><span class="line"></span><br><span class="line"><span class="comment"># 将收到的结果保存到data文件中</span></span><br><span class="line">nc -l 1234 &gt; data </span><br><span class="line"></span><br><span class="line"><span class="comment"># 实时发送数据(按ctrl+d结束)</span></span><br><span class="line">nc localhost 1234</span><br><span class="line"></span><br><span class="line"><span class="comment"># 实时发送数据（按指定字符结束）</span></span><br><span class="line">nc localhost 1234 &lt;&lt; EOF</span><br><span class="line">&gt; ...</span><br><span class="line">&gt; EOF</span><br><span class="line"></span><br><span class="line"><span class="comment"># 发送数据1</span></span><br><span class="line"><span class="built_in">echo</span> -n 1 |nc localhost 1234 </span><br><span class="line"></span><br><span class="line"><span class="comment"># 监听UDP端口</span></span><br><span class="line">nc -u -l 1234</span><br><span class="line"></span><br><span class="line"><span class="comment"># 发送UDP</span></span><br><span class="line">nc -u localhost 1234</span><br></pre></td></tr></table></figure>
<h5 id="有趣的应用"><a href="#有趣的应用" class="headerlink" title="有趣的应用"></a>有趣的应用</h5><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 扫描TCP端口</span></span><br><span class="line">nc localhost 1-100</span><br><span class="line"></span><br><span class="line"><span class="comment"># 扫描UDP端口</span></span><br><span class="line">nc -u localhost 1-100</span><br><span class="line"></span><br><span class="line"><span class="comment"># 模拟HTTP请求</span></span><br><span class="line">nc www.baidu.com 80</span><br><span class="line">GET / HTTP/1.1</span><br><span class="line">host: localhost</span><br><span class="line"></span><br><span class="line"><span class="comment"># 发送文件</span></span><br><span class="line">cat 1.log|nc localhost 1234</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/28/2017-09-28-百度语音识别/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/28/2017-09-28-百度语音识别/" itemprop="url">百度语音识别</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-28T00:00:00+08:00">
                2017-09-28
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/音视频/" itemprop="url" rel="index">
                    <span itemprop="name">音视频</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>随着亚马逊的Echo、Google的Home、京东的叮咚、阿里巴巴的天猫精灵的推出，都在市面上引起了不少波动，其中用到的关键技术就是语音识别. 关于语音识别，找到了百度语音识别，本文将给出该接口使用方法.</p>
<h3 id="注册百度账号，并创建应用"><a href="#注册百度账号，并创建应用" class="headerlink" title="注册百度账号，并创建应用"></a>注册百度账号，并创建应用</h3><p>访问<a href="http://yuyin.baidu.com/进行账号注册及应用创建，获取到AppKey、SecretKey、CUID" target="_blank" rel="noopener">http://yuyin.baidu.com/进行账号注册及应用创建，获取到AppKey、SecretKey、CUID</a></p>
<h3 id="API"><a href="#API" class="headerlink" title="API"></a>API</h3><p>访问 <a href="http://yuyin.baidu.com/docs/asr/57" target="_blank" rel="noopener">该地址</a> 即可了解到API使用说明</p>
<table>
<thead>
<tr>
<th style="text-align:left">字段名</th>
<th style="text-align:left">可需</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">format</td>
<td style="text-align:left">必填</td>
<td>语音文件的格式，pcm 或者 wav 或者 amr。不区分大小写</td>
</tr>
<tr>
<td style="text-align:left">rate</td>
<td style="text-align:left">必填</td>
<td>采样率，支持 8000 或者 16000</td>
</tr>
<tr>
<td style="text-align:left">channel</td>
<td style="text-align:left">必填</td>
<td>声道数，仅支持单声道，请填写固定值 1</td>
</tr>
<tr>
<td style="text-align:left">cuid</td>
<td style="text-align:left">必填</td>
<td>用户唯一标识，用来区分用户，计算UV值。建议填写能区分用户的机器 MAC 地址或 IMEI 码，长度为60字符以内。</td>
</tr>
<tr>
<td style="text-align:left">token</td>
<td style="text-align:left">必填</td>
<td>开放平台获取到的开发者 access_tokenn</td>
</tr>
<tr>
<td style="text-align:left">lan</td>
<td style="text-align:left">选填</td>
<td>语种选择，默认中文（zh）。 中文=zh、粤语=ct、英文=en，不区分大小写。</td>
</tr>
<tr>
<td style="text-align:left">url</td>
<td style="text-align:left">选填</td>
<td>语音下载地址，与callback连一起使用，确保百度服务器可以访问</td>
</tr>
<tr>
<td style="text-align:left">callback</td>
<td style="text-align:left">选填</td>
<td>识别结果回调地址，确保百度服务器可以访问</td>
</tr>
<tr>
<td style="text-align:left">speech</td>
<td style="text-align:left">选填</td>
<td>真实的语音数据 ，需要进行base64 编码。与len参数连一起使用。</td>
</tr>
<tr>
<td style="text-align:left">len</td>
<td style="text-align:left">选填</td>
<td>原始语音文件的字节数，单位字节</td>
</tr>
</tbody>
</table>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">POST http://vop.baidu.com/server_api</span><br><span class="line"></span><br><span class="line">Content-Type:application/json</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line">    <span class="string">"format"</span>:<span class="string">"speex"</span>,</span><br><span class="line">    <span class="string">"rate"</span>:8000,</span><br><span class="line">    <span class="string">"channel"</span>:1,</span><br><span class="line">    <span class="string">"token"</span>:xxx,</span><br><span class="line">    <span class="string">"cuid"</span>:<span class="string">"baidu_workshop"</span>,</span><br><span class="line">    <span class="string">"len"</span>:4096,</span><br><span class="line">    <span class="string">"speech"</span>:<span class="string">"xxx"</span>,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="实现"><a href="#实现" class="headerlink" title="实现"></a>实现</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 获取token</span></span><br><span class="line">access_token=`curl -s <span class="string">"https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&amp;client_id=<span class="variable">$BAIDU_YUYIN_API_KEY</span>&amp;client_secret=<span class="variable">$BAIDU_YUYIN_SECRET_KEY</span>"</span>|jshon -e access_token|sed <span class="string">'s/"//g'</span>`</span><br><span class="line">size=`/bin/ls -l <span class="variable">$pcmfile</span>|awk <span class="string">'&#123;print $5&#125;'</span>`</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> [ `myos` == <span class="string">'linux'</span> ];<span class="keyword">then</span></span><br><span class="line">    base64data=`base64 -w 0 <span class="variable">$pcmfile</span>`</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    base64data=`base64 <span class="variable">$pcmfile</span>`</span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line">body=<span class="string">"&#123;</span></span><br><span class="line"><span class="string">    \"format\":\"pcm\",</span></span><br><span class="line"><span class="string">    \"rate\":8000,</span></span><br><span class="line"><span class="string">    \"channel\":1,</span></span><br><span class="line"><span class="string">    \"token\":\"<span class="variable">$access_token</span>\",</span></span><br><span class="line"><span class="string">    \"cuid\":\"<span class="variable">$BAIDU_YUYIN_CUID</span>\",</span></span><br><span class="line"><span class="string">    \"len\":<span class="variable">$size</span>,</span></span><br><span class="line"><span class="string">    \"speech\":\"<span class="variable">$base64data</span>\"</span></span><br><span class="line"><span class="string">&#125;"</span></span><br><span class="line"></span><br><span class="line">result=`curl -s -H <span class="string">"Content-Type:application/json"</span> --data <span class="string">"<span class="variable">$body</span>"</span> <span class="string">"http://vop.baidu.com/server_api"</span>`</span><br><span class="line"><span class="keyword">if</span> [ `<span class="built_in">echo</span> <span class="variable">$result</span>|jshon -e err_no` -eq 0 ];<span class="keyword">then</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="variable">$result</span>|jshon -e result</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    error <span class="string">"fail. the result is <span class="variable">$result</span>"</span></span><br><span class="line"><span class="keyword">fi</span></span><br></pre></td></tr></table></figure>
<p>PS: jshon是json解析程序，可以访问<a href="https://raw.githubusercontent.com/smallmuou/sm-cli/master/commands/a2t" target="_blank" rel="noopener">https://raw.githubusercontent.com/smallmuou/sm-cli/master/commands/a2t</a> 获取全部源码</p>
<p>a2t使用方法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./a2t xxx.pcm</span><br></pre></td></tr></table></figure>
<p>PS: BAIDU_YUYIN_API_KEY、BAIDU_YUYIN_SECRET_KEY、BAIDU_YUYIN_CUID是在/etc/sm.conf配置</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/09/26/2017-09-26-使用bash编写pcm转wav脚本/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/09/26/2017-09-26-使用bash编写pcm转wav脚本/" itemprop="url">使用bash编写pcm转wav脚本</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-26T00:00:00+08:00">
                2017-09-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/音视频/" itemprop="url" rel="index">
                    <span itemprop="name">音视频</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>最近需要将一段pcm音频文件转换成wav，以进行播放，但没有发现类似命令，于是自己动手写了一个，现在已开源至github（<a href="https://github.com/smallmuou/wavutils）；大家知道使用c编写，难度非常小，只要填充头部44字节，并写入文件即可，我为什么用bash进行编写？这里考虑到bash脚本的几个有点：免编译、跨平台；因此对于bash脚本，可以做到「拿来即用」" target="_blank" rel="noopener">https://github.com/smallmuou/wavutils）；大家知道使用c编写，难度非常小，只要填充头部44字节，并写入文件即可，我为什么用bash进行编写？这里考虑到bash脚本的几个有点：免编译、跨平台；因此对于bash脚本，可以做到「拿来即用」</a>. 本文将只对关键技术点进行阐述，有兴趣的童鞋，可以查看源码.</p>
<ul>
<li>技术点1 - 10进制转16进制</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">hex</span></span>() &#123;</span><br><span class="line">    <span class="built_in">printf</span> <span class="string">"%0<span class="variable">$1x</span>"</span> <span class="variable">$2</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>利用printf来实现类似c printf的功能</p>
<ul>
<li>技术点2 - 获取文件大小</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">filesize</span></span>() &#123;  </span><br><span class="line">  /bin/ls -l <span class="variable">$1</span>|awk <span class="string">'&#123;print $5  &#125;'</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>技术点3 - 小端显示</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">little_endian</span></span>() &#123;</span><br><span class="line">    <span class="built_in">local</span> i</span><br><span class="line">    len=<span class="variable">$&#123;#1&#125;</span></span><br><span class="line">    <span class="keyword">for</span> (( i=<span class="variable">$len</span>; i&gt;=2; i=i-2 ))</span><br><span class="line">    <span class="keyword">do</span></span><br><span class="line">        <span class="built_in">echo</span> -n <span class="variable">$&#123;1:i-2:2&#125;</span></span><br><span class="line">    <span class="keyword">done</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>小端即低位显示在前，如0x1234，则显示0x34 0x12</p>
<ul>
<li>技术点4 - wav转pcm</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">wav2pcm</span></span>() &#123;</span><br><span class="line">    dd <span class="keyword">if</span>=<span class="variable">$1</span> of=<span class="variable">$2</span> bs=1 skip=44 &gt; /dev/null 2&gt;&amp;1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>利用dd skip跳过头部44字节即可</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/4/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/4/">4</a><span class="page-number current">5</span><a class="page-number" href="/blog/page/6/">6</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/20/">20</a><a class="extend next" rel="next" href="/blog/page/6/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">smallmuou</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">197</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/smallmuou" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-globe"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">smallmuou</span>

  
</div>

    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    <span id="busuanzi_container_site_pv">总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>



  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
